<?php
/**
 * 积分礼品管理
 * @author hushuai
 *
 */
class IntegralAction extends CommonAction{
	
	/**
	 * 积分礼品管理
	 */
	
	public function index(){
		
		
		if(IS_AJAX){
			$desc    = $this->_get("orderDirection","trim","desc");;
			$order   = $this->_get("orderName","trim","addtime");
			$pageNum = $this->_get("pageNum","intval",C('PAGE_NUMS'));
			$nowPage = $this->_get("p","intval",1);
			$where   = $this->_param("where","trim","");
			$restid  = $this->_get("id","intval",0);
			
			$map   = array("where"=>$where,"pageNum"=>$pageNum, "p"=>$nowPage, "orderDirection"=>$desc ,"orderName"=>$order);
			$json  = sendRest("RMS/Integral/index",$map,"post");
			
			$data  = $json['data'];
			$count = $data['count'];
	
			$totalPage = ceil($count/$pageNum);
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'totalPage'=>$totalPage);
			
			foreach($data['list'] AS $row){
				
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'           => $row['id'],
						'rtitle'       => $row['rtitle'],
						'title'        => $row['title'],
						'entitle'      => $row['entitle'],
						'integration'  => $row['integration'],
						'amount'       => $row['amount'],
						'addtime'      => date('Y-m-d',$row['addtime']),
					),
				);
				$jsonData['rows'][] = $entry;
			}
	
			$this->ajaxReturn($jsonData,"JSON");
		}else{
			
			$list = sendRest("BDC/Outlet/view");
			$this->assign("list", $list['data']);
			
			$id  = $this->_param("id","intval",0);
			$this->assign("id",$id);
			
			//所有菜系
			$cuisine = sendRest("BDC/Outlet/dictCuisine");
			$this->assign("cuisine",$cuisine['data']['array']);
			 
			$this->display();
		}
	}
	/**
	 * 添加积分礼品
	 */
	public function add(){
		
		if(IS_AJAX){
			
			$json   = sendRest("RMS/Integral/add", $_POST);	
			$this->ajaxReturn($json);
				
		}else{
	
			$map['id'] = $this->_param("id","intval",0);
			
			$jsons     = sendRest("BDC/Outlet/detail",$map);
			$list      = sendRest("BDC/Outlet/view");
			
			//所有菜系
			$cuisine = sendRest("BDC/Outlet/dictCuisine");
			$this->assign("cuisine",$cuisine['data']['array']);
			
			$this->assign("detail", $jsons['data']);
			$this->assign("list",   $list['data']);
	
			$this->display();
		}
		 
		 
	}
	/**
	 * 修改积分礼品
	 */
	public function edit(){
		 
		if(IS_AJAX){
			$json = sendRest("RMS/Integral/edit",$_POST);
			$this->ajaxReturn($json);
			 
		}else{
	
			$map['id']  = $this->_get("id","intval",0);
			$json       = sendRest("RMS/Integral/detail",$map);
			$this->assign("detail", $json['data']);
			
			$Out['id'] = $json['data']['restid'];
			$list      = sendRest("BDC/Outlet/view");
			$this->assign("list", $list['data']);
			
			$this->display();
		}
	}
	/**
	 * 删除积分礼品
	 */
	public function del(){
		 
		if(IS_AJAX){
	
			$map['id'] = $this->_get("id","intval",0);
			$json = sendRest("RMS/Integral/del",$map);
	
			$this->ajaxReturn($json);
		}
	}
	/**
	 * 批量删除积分礼品
	 */
	public function delall(){
			
		if(IS_AJAX){
	
			$map['val'] = $_POST['val'];
    		$data = sendRest("RMS/Integral/delall",$map);
    	
			$this->ajaxReturn($data);
		}
	}
	
}

?>